package com.dnjn.mes.biz.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.dnjn.mes.common.core.domain.AjaxResult;
import com.dnjn.mes.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.v3.oas.annotations.tags.Tag;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

import com.dnjn.mes.common.core.controller.BaseController;

import com.dnjn.mes.biz.service.IMesMessageService;
import com.dnjn.mes.biz.domain.MesMessage;

/**
 * <p>
 * 故障信息表 前端控制器
 * </p>
 *
 * @author Amber
 * @since 2023-08-04
 */
@Tag(name = "MesMessage 故障信息表", description = "故障信息表")
@RestController
@RequestMapping("/biz/mesMessage")
    public class MesMessageController extends BaseController {

    @Autowired protected IMesMessageService baseService;

@GetMapping("/get/{id}")
public AjaxResult get(@PathVariable Long id) {
        return success(baseService.getById(id));
        }

@PostMapping("/add")
public AjaxResult add(@Validated @RequestBody MesMessage domain) {
        domain.setCreateBy(getUsername());
        return toAjax(baseService.save(domain));
        }

@PutMapping("/edit")
public AjaxResult edit(@Validated @RequestBody MesMessage domain) {
        return toAjax(baseService.updateById(domain));
        }

@DeleteMapping("/{pkIds}")
public AjaxResult remove(@PathVariable Long[] pkIds) {
        baseService.removeBatchByIds(Arrays.asList(pkIds));
        return success();
        }

@PostMapping("/page")
public AjaxResult page(@RequestBody MesMessage domain, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        Page page = Page.of(current, size);
        Page<MesMessage> list = baseService.page(page, Wrappers.query(domain));
        return success(list);
        }

@PostMapping("/export")
public void export(HttpServletResponse response, MesMessage domain) {
        List<MesMessage> list = baseService.list(Wrappers.query(domain));
        ExcelUtil<MesMessage> util = new ExcelUtil<MesMessage>(MesMessage.class);
        util.exportExcel(response, list, "参数数据");
        }





        }